//
//  PushTaskEditController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/7.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "PushTaskEditController.h"

@interface PushTaskEditController ()

@property (nonatomic, strong) UITextView *textView;

@end

@implementation PushTaskEditController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.rightBtnTitle = @"完成";
    
    
    [self makeEditTitle];
    
    [self makeTextView];
    
    [self registKeyBoardNotofication];
}

- (void)makeEditTitle
{
    if (self.editType == TaskEditTypeOfDescription) {
        self.baseTitle = @"任务描述";
    }else if (self.editType == TaskEditTypeOfSendWord){
        self.baseTitle = @"任务寄语";
    }
}

- (void)makeTextView
{
    _textView = [UITextView new];
    _textView.text = _text;
    _textView.font = [UIFont systemFontOfSize:17.0f];
    _textView.layer.masksToBounds = YES;
    _textView.layer.cornerRadius = 5.0;
    _textView.layer.borderColor = [RGB(220, 220, 220) CGColor];
    _textView.layer.borderWidth = 1.0;
    [_textView becomeFirstResponder];
    [self.baseView addSubview:_textView];

}

/**
 注册键盘弹出通知
 */
- (void)registKeyBoardNotofication
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillShow:)
                                                 name:UIKeyboardWillShowNotification
                                               object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification
{
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];

    
    [_textView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(SCREEN_HEIGHT - 66 - keyboardRect.size.height);
    }];

}

- (void)clickRightButton
{
    [_textView resignFirstResponder];
    [self dismissViewControllerAnimated:NO completion:nil];
    if ([self.delegate respondsToSelector:@selector(clickDoneWithType:text:)]) {
        [self.delegate clickDoneWithType:self.editType text:_textView.text];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
